/*
 ============================================================================
 Name		: iReadAppUi.cpp
 Author	  : readever.cn
 Copyright   : Copyright 2009-2010
 Description : CiReadAppUi implementation
 ============================================================================
 */

// INCLUDE FILES
#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <f32file.h>
#include <s32file.h>
#include <hlplch.h>

#include <iRead_0xE30E97C2.rsg>

//#include "iRead_0xE30E97C2.hlp.hrh"
#include "iRead.hrh"
#include "iRead.pan"
#include "iReadApplication.h"
#include "iReadAppUi.h"
#include "iReadAppView.h"

#include "MyDataCenter.h"
#include "CStreamAudioEngine.h"
#include "hm\htmldialog.h"

MyDataCenter* iDataCenter = NULL;
CHtmlControl* gHtmlControl;

_LIT( KFileName, "C:\\private\\E30E97C2\\iRead.txt" );
_LIT( KText, "Hello World!");

// ============================ MEMBER FUNCTIONS ===============================
CStreamAudioEngine* mp3stream;

// -----------------------------------------------------------------------------
// CiReadAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CiReadAppUi::ConstructL()
	{
	int iFontUid;
	CEikonEnv::Static()->ScreenDevice()->AddFile(_L("c:\\system\\fonts\\readever.gdr"),iFontUid);
	
	// Initialise app UI with standard value.
	BaseConstructL(CAknAppUi::EAknEnableSkin);
	iDataCenter = MyDataCenter::NewL();
	
	gHtmlControl = CHtmlControl::NewL(NULL);
	gHtmlControl->SetMopParent(this);
	gHtmlControl->SetRect(ClientRect());
	gHtmlControl->SetExtentToWholeScreen();	
	gHtmlControl->SetEventObserver(iDataCenter);
	gHtmlControl->ActivateL();
	AddToStackL(gHtmlControl);
	
	iDataCenter->Init(gHtmlControl, NULL);
	
	mp3stream = CStreamAudioEngine::NewL();
	
	}
// -----------------------------------------------------------------------------
// CiReadAppUi::CiReadAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CiReadAppUi::CiReadAppUi()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CiReadAppUi::~CiReadAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CiReadAppUi::~CiReadAppUi()
	{
	if (iAppView)
		{
		delete iAppView;
		iAppView = NULL;
		}
	
	RemoveFromStack(gHtmlControl);
	delete gHtmlControl;
	
		delete mp3stream;
		delete iDataCenter;
	}
	
// -----------------------------------------------------------------------------
// CiReadAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CiReadAppUi::HandleCommandL(TInt aCommand)
	{
	switch (aCommand)
		{
		case EEikCmdExit:
		case EAknSoftkeyExit:
			{
	        //MyDataCenter::SuperHandleKeyEventL, already handle it.
//				iDataCenter->CancelLoading();
//		
//				if(iDataCenter->IsMenuVisible())
//					iDataCenter->HideMenu();
//		
//				if(iDataCenter->GoBack() == false)
//		            Exit();
			}
			break;

		case ECommand1:
			{
				iDataCenter->TestMe();
			}
			break;
		case ECommand2:
			{
			TestMe();
			}
			break;
		case EHelp:
			{

			CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
			HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
			}
			break;
		case EAbout:
			{

			CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog();
			dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
			HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
			dlg->QueryHeading()->SetTextL(*title);
			CleanupStack::PopAndDestroy(); //title
			HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
			dlg->SetMessageTextL(*msg);
			CleanupStack::PopAndDestroy(); //msg
			dlg->RunLD();
			}
			break;
		default:
			Panic(EiReadUi);
			break;
		}
	}
// -----------------------------------------------------------------------------
//  Called by the framework when the application status pane
//  size is changed.  Passes the new client rectangle to the
//  AppView
// -----------------------------------------------------------------------------
//
void CiReadAppUi::HandleStatusPaneSizeChange()
	{
	iAppView->SetRect(ClientRect());
	}

CArrayFix<TCoeHelpContext>* CiReadAppUi::HelpContextL() const
	{
#warning "Please see comment about help and UID3..."
	// Note: Help will not work if the application uid3 is not in the
	// protected range.  The default uid3 range for projects created
	// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so that they
	// can be self signed and installed on the device during testing.
	// Once you get your official uid3 from Symbian Ltd. and find/replace
	// all occurrences of uid3 in your project, the context help will
	// work. Alternatively, a patch now exists for the versions of 
	// HTML help compiler in SDKs and can be found here along with an FAQ:
	// http://www3.symbian.com/faq.nsf/AllByDate/E9DF3257FD565A658025733900805EA2?OpenDocument
	CArrayFixFlat<TCoeHelpContext>* array = new (ELeave) CArrayFixFlat<
			TCoeHelpContext> (1);
	CleanupStack::PushL(array);
	//array->AppendL(TCoeHelpContext(KUidiReadApp, KGeneral_Information));
	CleanupStack::Pop(array);
	return array;
	}

void CiReadAppUi::TestMe()
	{
	mp3stream->OpenL(_L("c:\\data\\test.mp3"));
	}
// End of File
